<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

require_once ( LIB_DIR.'search/abstractsearch.php');
/**
 * Description of shopsearch
 *
 * @author jszhang
 */
class moviesearch  extends abstractsearch {

    public function __construct($host = '127.0.0.1', $port = 9312){
        parent::__construct($host, $port);

        //override some member vars
        //$this->m_index = array( "shop_info_index", "shop_info_stemmed" );
        $this->m_index = array( "yyste_index" );
    }

    /**
     * override protected functions
     */
     
    //after some default value changed, invoke this function
    protected function initialize() {
		//clear all filters
		$this->m_sphinxClient->ResetFilters();
		$this->m_sphinxClient->ResetOverrides();
		$this->m_sphinxClient->ResetGroupBy();

        $this->m_sphinxClient->SetConnectTimeout ( 1 );
        $this->m_sphinxClient->SetMatchMode ( $this->m_matchMode );
        $this->m_sphinxClient->SetWeights ( array ( 100, 1 ) );

        //        if ( count($filtervals) )
        //            $cl->SetFilter ( $filter, $filtervals );
        //        if ( $groupby )
        //            $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
        //        if ( $sortby )
        //            $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );

        //        if ( $sortexpr )
        //            $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );

        //        if ( $distinct )
        //            $cl->SetGroupDistinct ( $distinct );
        //        if ( $select )
        //            $cl->SetSelect ( $select );

        $this->m_sphinxClient->SetRankingMode ( $this->m_ranker );
        $this->m_sphinxClient->SetArrayResult ( $this->m_isArrayResult );
        $this->m_perPage = MOVIE_PERPAGE;
    }

    //put your code here
    protected function printResult( $res ) {
        $result = array();
        
        $result['total'] = $res['total'];
        $result['total_found'] = $res['total_found'];
        $result['time'] = $res['time'];

//        print "Query stats:\n";
//        if ( is_array($res["words"]) )
//            foreach ( $res["words"] as $word => $info )
//                print "    '$word' found $info[hits] times in $info[docs] documents\n";
//        print "\n";
        
        if ( isset($res["matches"]) && is_array( $res["matches"] ) ) {
            $result['matchIds'] = array();
            foreach ( $res["matches"] as $docinfo ) {
                $result['matchIds'][] = $docinfo['id'];
            }
        }
        return $result;
    }
    
    protected function printGroupByResult( $res, $groupField ){
        return null;
    }
}
?>
